package GUI.gameWin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import game.Player;
import gamePlus.client.ClientRoundUnit;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;

import GUI.CardImages;
import GUI.gameWinOld.CardButton;

import carddeck.Card;
import carddeck.Suit;

public class CardButtonPlus extends CardButton {
	private ClientRoundUnit roundUnit;
	
	public CardButtonPlus(Player owner, ClientRoundUnit roundUnit, Card theCard, boolean bLast, boolean bHorizontal) {
		card = theCard;
		last = bLast;
		this.roundUnit=roundUnit;
		playerOwner=owner;
		card.setButton(this);
		setBorder(BorderFactory.createEmptyBorder());
		setContentAreaFilled(false);
		
		val=theCard.getCardRank().getValue();
		Suit cardSuit=theCard.getCardSuit();
		if(cardSuit==Suit.HEARTS)
			;
		else if(cardSuit==Suit.DIAMONDS)
			val+=13;
		else if(cardSuit==Suit.CLUBS)
			val+=26;
		else if(cardSuit==Suit.SPADES)
			val+=39;
		else//Joker
			val=0;
		
		cardString = "/carddeck/conv/resized";
		if(bHorizontal)
			if(bLast)
				cardString+="H/";
			else
				cardString+="H/cutH/";
		else
			if(bLast)
				cardString+="V/";
			else
				cardString+="V/cutV/";

		ImageIcon img;
		if(bLast)
			img = CardImages.getInstance().getII(cardString+val);
		else
			img = CardImages.getInstance().getII(cardString+val);
		if(img==null)
			System.out.println("setting null!");
		setIcon(img);
		repaint();
		revalidate();
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				selectCardActionPerformed(evt);
			}
		});
	}

	public void setHighlighted(boolean hl) {
		ImageIcon img;
		if(!hl) {
			if(last)
				img = CardImages.getInstance().getII(cardString+val);
			else
				img = CardImages.getInstance().getII(cardString+val);
			setIcon(img);
		}
		else {
			img = CardImages.getInstance().getII(cardString+"HL_B/"+val);
			setIcon(img);
		}
	}
	
	public void selectCardActionPerformed(ActionEvent evt) {
		roundUnit.selectCardActionPerformed(getCard(), false);
	}
	
	public Card getCard() {
		return card;
	}
}
